﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using Lime49;
using System.Collections;

namespace LockCrypt_WM {
    /// <summary>
    /// Enables parsing from JSON using Json.NET
    /// </summary>
    public class JSONAccountType {
        public string ID { get; set; }
        public string Name { get; set; }
        public bool IsProtected { get; set; }
        public bool ShowNotes { get; set; }
        public string[] Fields { get; set; }
        public JSONAccountType() { }
        /// <summary>
        /// Enables easier serialization to JSON.
        /// </summary>
        /// <param name="type">The type.</param>
        public JSONAccountType(AccountType type) {
            this.ID = type.ID;
            this.Name = type.Name;
            this.ShowNotes = type.ShowNotes;
            this.IsProtected = type.IsProtected;
            this.Fields = type.Fields;
        }
    }
    /// <summary>
    /// Enables parsing from JSON using Json.NET
    /// </summary>
    public class JSONAccount {
        public string Name { get; set; }
        public string Type { get; set; }
        public string TypeID { get; set; }
        public string Icon { get; set; }
        public string Parent { get; set; }
        public string Created { get; set; }
        public string Modified { get; set; }
        public bool ShowNotes { get; set; }
        public string Notes { get; set; }
        public Dictionary<string, string>[] Fields { get; set; }
        public JSONAccount() { }
        /// <summary>
        /// Enables easier serialization to JSON.
        /// </summary>
        /// <param name="account">The account.</param>
        public JSONAccount(Account account) {
            this.Name = account.Name;
            this.Type = account.Type;
            this.TypeID = account.TypeID;
            this.Icon = account.Icon;
            this.Parent = account.Parent;
            this.Created = Utils.DateTimeToUNIXTime(account.Created).ToString();
            this.Modified = Utils.DateTimeToUNIXTime(account.Modified).ToString();
            this.Fields = new Dictionary<string, string>[account.Fields.Count];
            int i = 0;
            foreach(DictionaryEntry field in account.Fields) {
                this.Fields[i] = new Dictionary<string, string> {
                        {"Name", field.Key.ToString()},
                        {"Value", field.Value.ToString()}
                    };
                i++;
            }
            /*for(int i=0;i<Fields.Length;i++) {
            //foreach(DictionaryEntry field in account.Fields) {
                this.Fields[i] = new Dictionary<string, string>{
                    {"Name", account.Fields.Values.ToString()},
                    {"Value", thisField.Value.ToString()}
                };
                //this.Fields.Add(field["Name"], field[""]);
            }*/
            this.ShowNotes = account.ShowNotes;
            this.Notes = account.Notes;
        }
    }
    /// <summary>
    /// Enables parsing from JSON using Json.NET
    /// </summary>
    public class JSONGroup {
        public string Name { get; set; }
        public string Parent { get; set; }
        public string Created { get; set; }
        public string Modified { get; set; }
        public JSONGroup() { }
        /// <summary>
        /// Enables easier serialization to JSON.
        /// </summary>
        /// <param name="group">The group.</param>
        public JSONGroup(Group group) {
            this.Name = group.Name;
            this.Parent = group.Parent;
            this.Created = Utils.DateTimeToUNIXTime(group.Created).ToString();
            this.Modified = Utils.DateTimeToUNIXTime(group.Modified).ToString();
        }
    }
}
